package com.wzh.store.config;

import com.wzh.store.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author wzh
 * @create 2022/4/16 14:32
 * @Description： 处理器拦截器功能的注册
 */
@Configuration//加载当前的拦截器并注册
public class LoginInterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        HandlerInterceptor interceptor=new LoginInterceptor();
        List<String> list=new ArrayList<>();
        list.add("/bootstrap3/**");
        list.add("/css/**");
        list.add("/images/**");
        list.add("/js/**");
        list.add("/web/login.html");
        list.add("/web/index.html");
        list.add("/web/register.html");
        list.add("/web/product.html");
        list.add("/users/reg");
        list.add("/users/login");
        list.add("/districts/**");
        list.add("/products/**");
        list.add("/carts/**");
        registry.addInterceptor(interceptor).addPathPatterns("/**")
                .excludePathPatterns(list);
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
